package com.exercises;


import com.exercises.common.TreeNode;

/**
 * 并归排序
 */
class Exercise783 {
    Integer rootValue = null;
    Integer min = Integer.MAX_VALUE;


    public int minDiffInBST(TreeNode root) {
        dfs(root);
        return min;
    }

    public void dfs(TreeNode node) {
        if (node == null) return;
        dfs(node.left);

        if (rootValue != null) {
            min = Math.min(min, rootValue - node.val);
        }
        rootValue = node.val;

        dfs(node.right);

    }

}

